<?php
class UserModel extends Model{

	public function __construct(){}

	public function getUserById( $user_id ){
		$sql = "SELECT * FROM users WHERE user_id = ? AND status = 1";
		parent::getDb()->_db->query( $sql, array($user_id) );
		return parent::getDb()->_db->fetch();
	}

	public function getUser( $email ){
		$sql = "SELECT * FROM users where email = ? and status = 1";
		parent::getDb()->_db->query($sql, array($email));
		return parent::getDb()->_db->fetch();
	}

	public function getUserByLogin( $email, $password ){
		$sql = "SELECT * FROM users where email = ? and password = ?";
		parent::getDb()->_db->query($sql, array($email,$password));
		return parent::getDb()->_db->fetch();
	}
	
	public function create( $options ){
		$sql = "INSERT INTO users";
		$sql_pre = "";
		$sql_ext = "";
		$count = count($options);

		if(is_array($options) && $count > 0){
			$i = 0;
			foreach($options as $key=>$val){
				$i++;
				$sql_pre .= '`'.$key.'`';
				$sql_ext .= "?";
				if($i < $count ){
					$sql_pre .= ',';
					$sql_ext .= ',';
				}
			}
			$sql = $sql.'('.$sql_pre.') VALUES('.$sql_ext.')';
			parent::getDb()->_db->query($sql, $options);
			return parent::getDb()->_db->insert();
			
		}else{
			return 0;
		}
	}
}
